package cn.com.gzheroli.rabbitmq.service.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.gzheroli.core.holder.SpringContextHolder;

import javax.annotation.Resource;

/**
 * Created by lhx on 2016/9/5 9:56
 *
 * @Description
 */
@Service
public class TopicProducerService {

    private Logger logger = LoggerFactory.getLogger(TopicProducerService.class);

    /*@Resource
    private AmqpTemplate topicTemplate;*/
    @Autowired
    private RabbitTemplate topicTemplate;

    /*public void sendMessage(Object message){
        logger.info("to send message:{}",message);
        topicTemplate.convertAndSend("info.debug",message);
    }*/
    public void sendMessage1(Object message){
    	//RabbitTemplate template = (RabbitTemplate) SpringContextHolder.getBean("topicTemplate");
    	/*topicTemplate.convertAndSend(topicTemplate.getExchange(), "ccs.binding.test", "id=111111",new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setHeader("jobName", "jobName");
                return message;
            }
        });*/
    	//topicTemplate.convertAndSend(topicTemplate.getExchange(),"id=111111");
        String exchange=topicTemplate.getExchange();
        String routingKey="ccs.binding.test";
        topicTemplate.convertAndSend(exchange, routingKey, message);
    }
    
}
